// pages/wuliurongqiguanli/nav_problem_search/problem_search.js
const mybehavior = require("../../../behaviors/requests")
Page({
  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    page_all: 0,
    total: 0,
    baseUrl: "https://logisticsengineering.gree.com/container_manage_api/container_manage",
    current_page: 1,
    username: "",
    activeName: [],
    flag: false,
    data_list: [],
    detail_show: false,
    detail_list: []
  },
  onChange(event) {
    this.setData({
      activeName: event.detail,
    });
  },

  pageUp() {
    var now_page = this.data.current_page
    if (now_page != 1) {
      now_page = now_page - 1
      this.setData({
        current_page: now_page
      })
      this.getDatas()
    }


  },
  pageDown() {
    var now_page = this.data.current_page
    if (now_page < this.data.page_all) {
      now_page = now_page + 1
      this.setData({
        current_page: now_page
      })
      this.getDatas()
    }

  },
  // 查询数据
  getDatas() {
    var url = this.data.baseUrl + "/problem_search"
    var data = {
      current_page: this.data.current_page
    }
    this.post(url, data).then(res => {
      console.log("返回结果", res)
      if (res.code == 20000) {
        this.setData({
          data_list: res.data.items,
          total: res.data.total_items,
          page_all: Math.ceil(res.data.total_items / 5)
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 预览照片
  previewPhoto(e) {
    console.log(e.currentTarget.dataset.row_data)
    var img_url = 'https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=' + e.currentTarget.dataset.row_data
    var u = []
    u.push(img_url)
    wx.previewImage({
      current: img_url,
      urls: u,
    })
  },
  // 打开补充问题详情
  showDetail(e) {
    console.log(e.currentTarget.dataset.row_data.live_record)
    this.setData({
      detail_show: true,
      detail_list: e.currentTarget.dataset.row_data.live_record
    })
  },
  // 详情弹窗关闭
  detailConfirm() {
    this.setData({
      detail_show: false,
      detail_list: ""
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDatas()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})